package fr.mairie.parc.control.attribution;

import org.apache.click.control.FieldSet;
import org.apache.click.control.Form;
import org.apache.click.extras.control.IntegerField;

import fr.mairie.parc.domain.Attribution;

public class AttributionFields {

	private boolean withIdField;
	private IntegerField idAttribution = new IntegerField ("idAttribution", "ID");
	private FieldSet fieldset = new FieldSet("attributionFieldset", "Attribution");
	private IntegerField idDemande = new IntegerField("idDemande", "idDemande");
	private IntegerField idUser = new IntegerField("idUser", "idUser");
	private IntegerField idMateriel = new IntegerField("idMateriel", "idMateriel");


	public AttributionFields (boolean withIdField) {
		this.withIdField = withIdField;

		if (withIdField) {
			fieldset.add(idAttribution);
		}

		fieldset.add(idDemande);
		fieldset.add(idUser);
		fieldset.add(idMateriel);
	}

	public void addAll(Form form) {
		form.add(fieldset);
	}

	public void setReadonly(boolean disabled) {
		fieldset.setReadonly(disabled);
	}

	public void getFieldsValues(Attribution in) {
		if (withIdField) {
			in.setIdAttribution(idAttribution.getInteger());
		}
		in.setIdDemande(idDemande.getInteger());
		in.setIdDemande(idUser.getInteger());
		in.setIdDemande(idMateriel.getInteger());

	}

	public void setFieldsValues(Attribution src) {
		if (withIdField) {
			idAttribution.setInteger(src.getIdAttribution());
		}
		idDemande.setInteger(src.getIdDemande());
		idUser.setInteger(src.getIdUser());
		idMateriel.setInteger(src.getIdMateriel());
	}

	public void setIdAttribution(Attribution src) {
		idAttribution.setInteger(src.getIdAttribution());
	}

	public int getIdAttribution() {
		return idAttribution.getInteger();
	}

}
